import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:smart_translator/app/event/DataCallBack.dart';
import 'package:smart_translator/app/style/widget_style.dart';
import 'package:smart_translator/app/utils/CommonUtil.dart';
import 'package:smart_translator/app/widgets/CommonWidgets.dart';

import '../../../style/app_colors.dart';
import '../../../views/controller/RecordTranscriptViewRecordingController.dart';
import '../../../views/views/record2script_q_and_a_ai.dart';
import '../../../views/views/record2script_record2text.dart';
import '../../../views/views/record2script_sumerise.dart';
import '../../../widgets/AppHeader.dart';
import '../controllers/recordscript_detail_controller.dart';

class RecordscriptDetailView extends GetView<RecordscriptDetailController> {
  RecordscriptDetailView({super.key});

  Record2scriptQandAai record2scriptQandAai = Record2scriptQandAai();
  Record2scriptRecord2text record2scriptRecord2text = Record2scriptRecord2text();
  Record2scriptSumerise record2scriptSumerise = Record2scriptSumerise();
  PageController pageController = PageController(initialPage:1);



  @override
  Widget build(BuildContext context) {
    RecordTranscriptViewRecordingController record =
    Get.find<RecordTranscriptViewRecordingController>();

    return SafeArea(
        top: false,
        child: Scaffold(
        body: Stack(
          children: [
            Container(
              child: SvgPicture.asset(
                "assets/images/header_part_bg.svg",
                width: Get.width,
              ),
            ),
            AppHeader.obtainHeaderForRecordScriptDetail(controller.audioType!,
                DataCallBack(
                    confirmCallBack: (v) {
                      controller.quite();
                    },
                    businessCallBack: (v) {
                      // 浮窗显示.
                      controller.showFloatingWindow(Get.context!);
                    }
                )
            ),
            Obx(()=> Container(
              width: Get.width,
              height: Get.height,
              margin: EdgeInsets.only(top: 95.h),
              child: ListView(
                // mainAxisSize: MainAxisSize.min,
                controller: controller.scrollController,
                physics: const BouncingScrollPhysics(
                  parent: AlwaysScrollableScrollPhysics(),
                ),
                padding: EdgeInsets.zero,
                children: [
                  controller.audioType == 'new'? SizedBox(): AnimatedContainer(
                    duration: const Duration(milliseconds: 500),
                    curve: Curves.easeInOut,
                    height: controller.isHeaderVisible.value ? 140.h : 0,

                    padding: EdgeInsets.only(left: 20.w,right: 20.w,top: 20.h,bottom: 1.h),
                    child: Container(
                      alignment: Alignment.center,
                      child: ListView(
                        padding: EdgeInsets.zero,
                        children: [
                          Container(
                            width: MediaQuery.of(context).size.width,
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.all(Radius.circular(20.h)),
                                color: Colors.white
                            ),
                            child: AudioFileWaveforms(
                              waveformType: WaveformType.fitWidth,
                              size: Size(Get.width, 20.h),
                              playerController: controller.playerController,
                              playerWaveStyle: PlayerWaveStyle(
                                  fixedWaveColor: Colors.grey,
                                  liveWaveColor: AppColors.app_base_theme_color,
                                  spacing: 6,
                                  scaleFactor: 100,
                                  scrollScale: 1.2,
                              ),
                              padding: EdgeInsets.only(right: 10.w),
                            ),
                          ),
                          SizedBox(height: 5.h,),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text('${controller.currentFileDuration}',style: TextStyle(
                                  fontSize: 12.sp,
                                  color: AppColors.second_title_color
                              ),),
                              Text('${controller.fileLengthInDuration}',style: TextStyle(
                                  fontSize: 12.sp,
                                  color: AppColors.second_title_color
                              ))
                            ],
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            children: [
                              InkWell(
                                onTap: () {
                                    controller.justifyAudioSpeed();
                                },
                                child: Container(
                                  child: Column(
                                    children: [
                                      SvgPicture.asset('${controller.speed_icon_path.value}',width: 24.w,height: 24.h,),
                                      SizedBox(height: 10.h,),
                                      Text('播放速度',
                                        style: TextStyle(
                                            fontSize: 12.sp,
                                            color: AppColors.second_title_color
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              InkWell(
                                onTap: () {
                                   controller.backwardSeconds10();
                                },
                                child: Container(
                                  child: Column(
                                    children: [
                                      Image.asset('assets/images/icon_transcript_audio_back_seconds.png',width: 24.w,height: 24.h,),
                                      SizedBox(height: 10.h,),
                                      Text('后退10秒',
                                        style: TextStyle(
                                            fontSize: 12.sp,
                                            color: AppColors.second_title_color
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              InkWell(
                                onTap: () {
                                    if (controller.audioPlay.value) {
                                      controller.pauseAudioFromDeviceFile();
                                    } else {
                                      controller.playAudioFromDeviceFile();
                                    }
                                },
                                child: Container(
                                  child: Column(
                                    children: [
                                      controller.audioPlay.value? Image.asset('assets/images/icon_play_realtime_btn_running.png',width: 48.w,height: 48.h) :
                                       Image.asset('assets/images/icon_play_realtime_btn.png',width: 48.w,height: 48.h),
                                      SizedBox(height: 10.h,),
                                      Text('${controller.currentFileDuration}',
                                        style: TextStyle(
                                            fontSize: 12.sp,
                                            color: AppColors.second_title_color
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              InkWell(
                                onTap: () {
                                    controller.forwardSeconds10();
                                },
                                child: Container(
                                  child: Column(
                                    children: [
                                      Image.asset('assets/images/ico_transcript_audio_forward_seconds.png',width: 24.w,height: 24.h,),
                                      SizedBox(height: 10.h,),
                                      Text('快进10秒',
                                        style: TextStyle(
                                            fontSize: 12.sp,
                                            color: AppColors.second_title_color
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                              Container(
                                child: Column(
                                  children: [
                                    Text('',
                                      style: TextStyle(
                                          fontSize: 12.sp,
                                          color: AppColors.second_title_color
                                      ),
                                    )
                                  ],
                                ),
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 18.w,top: 20.h,right: 18.w,bottom: 10.h),
                    child: Row(
                      children: [
                        Text('${controller.session.value.session_name}',style: TextStyle(
                            fontSize: 21.sp,
                            fontWeight: FontWeight.w900

                        ),),
                        SizedBox(width: 20.w,),
                        InkWell(
                          onTap: () {
                            controller.changeSessionName();
                          },
                          child: Container(
                            padding: EdgeInsets.only(right: 20.w,top: 10.h,bottom: 10.h),
                            child:  Image.asset('assets/images/icon_record_scription_edition.png',width: 13.w,height: 13.h),
                          ),
                        )
                      ],
                    ),
                  ),
                  SizedBox(height: 10.h,),
                  Container(
                    margin: EdgeInsets.only(left: 18.w,right: 18.w),
                    child: Column(
                      children: [
                        Row(children: [
                          Image.asset('assets/images/icon_record_script_canlender.png',width: 16.w, height: 16.h,),
                          Text('${CommonUtil.formatCustomWeekday(controller.session.value.create_time)}',style: AppStyleThemeData.HINT_TEXT_STYLE_small,),
                          SizedBox(width: 16.w,),
                          InkWell(
                            onTap: () {
                              controller.moveFolder(isQuitePage: false);
                            },
                            child: Container(
                              child: Row(
                                children: [
                                  Image.asset('assets/images/icon_sildeside_blue_folder.png',width: 16.w, height: 16.h,),
                                  SizedBox(width: 5.w,),
                                  Text('${controller.folderName.value}',style: TextStyle(
                                      color: Colors.blueAccent,
                                      fontWeight: FontWeight.w600
                                  ),),
                                ],
                              ),
                            ),
                          ),
                          SizedBox(width: 16.w,),

                        ],),
                        //SizedBox(height: 10.h,),

                      ],
                    ),
                  ),
                  SizedBox(height: 16.h,),
                  Column(
                    children: [
                      Row(
                        children: [
                          Expanded(child:
                          GestureDetector(
                            onTap: () {
                              pageController.jumpToPage(0);
                              controller.onPageChanged(0);
                            },
                            child: Container(
                              color: Colors.red.withValues(alpha: 0),
                              child: Center(
                                child: Text('总结',style: TextStyle(
                                    color: controller.summeryChecked.value? Colors.blueAccent: AppColors.hint_text_color.withValues(alpha: 0.4),
                                    fontSize: 14.sp
                                )),
                              ),
                              padding: EdgeInsets.only(bottom: 10.h,top: 10.h),
                            ),
                          ),
                          flex: 1,),
                          Expanded(child: GestureDetector(
                            onTap: () {
                              pageController.jumpToPage(1);
                              controller.onPageChanged(1);
                            },
                            child: Container(
                              color: Colors.red.withValues(alpha: 0),
                              child: Center(
                                child: Column(
                                  children: [
                                    Text('录音转写',style: TextStyle(
                                        color: controller.recordSCriptChecked.value? Colors.blueAccent: AppColors.hint_text_color.withValues(alpha: 0.4),
                                        fontSize: 14.sp,
                                        fontWeight: FontWeight.w600
                                    )),
                                  ],
                                ),
                              ),
                              padding: EdgeInsets.only(bottom: 10.h,top: 10.h),
                            ),
                          ),flex: 1,),
                          Expanded(child: GestureDetector(
                            onTap: () {
                              pageController.jumpToPage(2);
                              controller.onPageChanged(2);
                            },
                            child: Container(
                              color: Colors.red.withValues(alpha: 0),
                              child: Center(
                                child: Text('AI问答',style: TextStyle(
                                    color: controller.aiAnswerChecked.value? Colors.blueAccent: AppColors.hint_text_color.withValues(alpha: 0.4),
                                    fontSize: 14.sp
                                )),
                              ),
                              padding: EdgeInsets.only(bottom: 10.h,top: 10.h),
                            ),
                          ),flex: 1),
                        ],
                      ),
                      Row(
                        children: [
                          Expanded(child: Container(
                            width: 88.w,
                            height: 3.h,
                            child: SizedBox(),
                            color: controller.summeryChecked.value ? Colors.blueAccent: Colors.blueAccent.withValues(alpha: 0),
                          ),flex: 1,),
                          Expanded(child: Container(
                            width: 88.w,
                            height: 3.h,
                            color: controller.recordSCriptChecked.value ? Colors.blueAccent: Colors.blueAccent.withValues(alpha: 0),
                            child: SizedBox(),
                          ),flex: 1,),
                          Expanded(child: Container(
                            width: 88.w,
                            height: 3.h,
                            child: SizedBox(),
                            color: controller.aiAnswerChecked.value ? Colors.blueAccent: Colors.blueAccent.withValues(alpha: 0),
                          ),flex: 1,),
                        ],
                      ),
                      CommonWidgets.getMyDivider()
                    ],
                  ),
                  Container(
                    height: 550.h,
                    child: PageView(
                      controller: pageController,
                      onPageChanged: (pageIndex) {
                        controller.onPageChanged(pageIndex);
                      },
                      children: [
                        record2scriptSumerise,
                        record2scriptRecord2text,
                        record2scriptQandAai
                      ],
                    ),
                  )

                ],
              ),
            ))
          ],
        )
    ));
  }

}
